home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 61 / Quick PC 61.iso / I386 / SASETUP.MSI / F77684_log_details.asp < prev    next >
Encoding:
Text File  |  2003-02-21  |  16.7 KB  |  518 lines

  1. <% @Language=VbScript%>
  2. <% Option Explicit    %>
  3. <%  
  4.     '-------------------------------------------------------------------------
  5.     ' Log_details.asp : This page displays the details of a selected log event
  6.     ' Copyright (c) Microsoft Corporation.  All rights reserved. 
  7.     '-------------------------------------------------------------------------
  8. %>    
  9.     <!--  #include virtual="/admin/inc_framework.asp"--->    
  10.     <!--  #include file="loc_event.asp"--->
  11.     <!--  #include file="inc_log.asp"-->
  12. <% 
  13.         
  14.     '-------------------------------------------------------------------------
  15.     ' Global Variables
  16.     '-------------------------------------------------------------------------
  17.     Dim G_strLogName            'Logname in WMI
  18.     Dim G_intRecordNumber        'Current record number of the event
  19.     Dim G_intMaxRecords            'Maximum records in the log
  20.     Dim G_strDescription        'Description of an Event
  21.     Dim G_objService            'object to WMI service
  22.     Dim G_btnClicked            'Flag to indicate Ok button not used
  23.     Dim G_intLowestRec            'Lowest record for the log
  24.     Dim page                    'Variable that receives the output page object when 
  25.                                 'creating a page 
  26.     Dim rc                        'Return value for CreatePage
  27.     
  28.     '-------------------------------------------------------------------------
  29.     ' Global Form Variables
  30.     '-------------------------------------------------------------------------
  31.     Dim F_strDate                'Start date of Event
  32.     Dim F_strTime                'Start time of Event
  33.     Dim F_strType                'Type of selected Event
  34.     Dim F_strSource                'SourceName of Event
  35.     Dim F_intEventid            'Event Identifier
  36.     Dim F_strDescription        'Description of the Event
  37.     
  38.     Dim F_strPrev                'To capture Pkey of the previous page 
  39.     Dim F_strTitle                'To capture Log Title from previous page
  40.     Dim arrTitle(1)
  41.         
  42.     F_strPrev  = Request.QueryString("Pkey")
  43.     F_strTitle = Request.QueryString("Title")
  44.     
  45.     G_intRecordNumber = Cint(F_strPrev)
  46.     G_strLogName    = F_strTitle
  47.     
  48.     'Localisation of page title
  49.     arrTitle(0) = GetLocalizationTitle(F_strTitle)
  50.     
  51.     'Page title
  52.     L_PAGETITLE_LOGDETAILS_TEXT = SA_GetLocString("event.dll", "403F006E", arrTitle)
  53.       
  54.     ' Create and show the page
  55.     Call SA_CreatePage(L_PAGETITLE_LOGDETAILS_TEXT, "", PT_AREA, Page)
  56.     Call SA_ShowPage(Page)
  57.     
  58.         
  59.     '-------------------------------------------------------------------------
  60.     'Function:                OnInitPage()
  61.     'Description:            Called to signal first time processing for this page.
  62.     '                        Use this method to do first time initialization tasks
  63.     'Input Variables:        PageIn,EventArg
  64.     'Output Variables:        None
  65.     'Returns:                True/False
  66.     'Global Variables:        G_btnClicked
  67.     '-------------------------------------------------------------------------
  68.     Public Function OnInitPage(ByRef PageIn,ByRef EventArg)
  69.         OnInitPage=TRUE
  70.     End Function
  71.     
  72.     '-------------------------------------------------------------------------
  73.     'Function:                OnServePropertyPage()
  74.     'Description:            Called when the page needs to be served.Use this 
  75.     '                        method to serve content
  76.     'Input Variables:        PageIn,EventArg
  77.     'Output Variables:        None
  78.     'Returns:                True/False
  79.     'Global Variables:        Input: G_btnClicked,L_(*),F_strDate,G_intRecordNumber,G_intMaxRecords
  80.     '                        F_strTime,F_strType,F_strSource,F_intEventid,G_strLogName
  81.     '-------------------------------------------------------------------------
  82.     Public Function OnServeAreaPage(ByRef PageIn,Byref EventArg)
  83.         Dim sDisabled
  84.         Dim oEncoder
  85.  
  86.         Set oEncoder = new CSAEncoder
  87.         
  88.         OnServeAreaPage=True              
  89.         
  90.         If ( Len(Request.Form("hdnRecordNum")) > 0 ) Then 
  91.             Call GetFormVariables()
  92.         Else
  93.             Call GetDefaultValues()
  94.         End if    
  95. %>    
  96.         <br>
  97.         <div class='PageBodyInnerIndent'>
  98.             <table border=0>
  99.                 <tr>
  100.                     <td nowrap class="TasksBody"><%=oEncoder.EncodeElement(L_DATE_DETAILS_TEXT)%></td>
  101.                     <td nowrap class="TasksBody"><%=oEncoder.EncodeElement(Cdate(F_strDate))%></td>
  102.                     <td>
  103.                     <%
  104.                         If trim(G_intRecordNumber) = trim(G_intMaxRecords)  Then
  105.                             sDisabled = "DISABLED"
  106.                         Else
  107.                             sDisabled = ""
  108.                         End If
  109.                         Call SA_ServeOnClickButtonEx(L_UPBUTTON_TEXT, "", "goNext()", 90, 0, sDisabled, "UpButton")
  110.                     %>
  111.                     
  112.                     </td>
  113.                 </tr>
  114.                 <tr>
  115.                     <td nowrap class="TasksBody"><%=oEncoder.EncodeElement(L_TIME_DETAILS_TEXT)%></td>
  116.                     <td nowrap class="TasksBody"><%=oEncoder.EncodeElement(Cdate(F_strTime))%></td>
  117.                     <td>
  118.                     <% 
  119.                         If G_intRecordNumber = G_intLowestRec  Then
  120.                             sDisabled = "DISABLED"
  121.                         Else
  122.                             sDisabled = ""
  123.                         End If
  124.                         Call SA_ServeOnClickButtonEx(L_DOWNBUTTON_TEXT, "", "goPrevious()", 90, 0, sDisabled, "DownButton")
  125.                     %>
  126.                     </td>
  127.                 </tr>
  128.                 <tr>
  129.                     <td nowrap class="TasksBody"><%=oEncoder.EncodeElement(L_TYPE_LABEL_TEXT)%></td>
  130.                     <td class="TasksBody"  nowrap><%=oEncoder.EncodeElement(F_strType)%></td>
  131.                     <td class="TasksBody"> </td>
  132.                 </tr>
  133.                 <tr>
  134.                     <td nowrap class="TasksBody"><%=oEncoder.EncodeElement(L_SOURCE_DETAILS_TEXT)%></td>
  135.                     <td class="TasksBody"  nowrap><%=oEncoder.EncodeElement(F_strSource)%></td>
  136.                     <td class="TasksBody"> </td>
  137.                 </tr>
  138.                 <tr>
  139.                     <td nowrap class="TasksBody"><%=oEncoder.EncodeElement(L_EVENTID_TEXT)%></td>
  140.                     <td class="TasksBody"  nowrap><%=oEncoder.EncodeElement(F_intEventid)%></td>
  141.                     <td class="TasksBody"> </td>
  142.                 </tr>
  143.                 <tr>
  144.                     <td class="TasksBody"> </td>
  145.                     <td class="TasksBody"> </td>
  146.                     <td class="TasksBody"> </td>
  147.                 </tr>
  148.                 <tr>
  149.                     <td nowrap class="TasksBody">
  150.                         <%=oEncoder.EncodeElement(L_DESCRIPTION_TEXT)%>
  151.                     </td>
  152.                 </tr>
  153.                 <tr>
  154.                     <td align="left" colspan=3 nowrap class="TasksBody">
  155.                         <textarea rows=5 cols=60 readonly id=textdescription name=textdescription><%=oEncoder.EncodeElement(F_strDescription)%></textarea>
  156.                     </td>
  157.                 </tr>
  158.                 <tr>
  159.                     <td class="TasksBody"> </td>
  160.                     <td class="TasksBody"> </td>
  161.                     <td class="TasksBody"> </td>
  162.                 </tr>
  163.                 <tr>
  164.                     <td class="TasksBody"> </td>
  165.                     <td class="TasksBody"> </td>
  166.                     <td class="TasksBody"> </td>
  167.                 </tr>
  168.             </table>
  169.         </div>        
  170.         
  171.         <input type="hidden" name="hdnLogName" value="<%=G_strLogName%>">
  172.         <input id="hdnRecordNum" type="hidden" name="hdnRecordNum" value="<%=G_intRecordNumber%>">
  173.         <input id="hdnMaxRecords" type="hidden" name="hdnMaxRecords" value="<%=G_intMaxRecords%>">
  174.         <input type="hidden" name="hdnMinRecords" value="<%=G_intLowestRec%>">
  175.  
  176. <%    
  177.         Call ServeCommonJavaScript()
  178.     
  179.     End Function
  180.     
  181.     
  182.     '-------------------------------------------------------------------------
  183.     'Function:                ServeCommonJavaScript
  184.     'Description:            Serves in initialiging the values,setting the form
  185.     '                        data and validating the form values
  186.     'Input Variables:        None
  187.     'Output Variables:        None
  188.     'Returns:                None
  189.     'Global Variables:        None
  190.     '-------------------------------------------------------------------------
  191.     Function ServeCommonJavaScript()
  192.     
  193. %>
  194.     <script language="JavaScript" src ='<%=m_VirtualRoot%>inc_global.js'>
  195.     </script>
  196.     <script language="JavaScript">
  197.             
  198.             // Set the initial form values
  199.             function Init()
  200.             {   
  201.                 return true
  202.             }
  203.                            
  204.             //function to next consecutive event
  205.             function goNext()
  206.             {
  207.                 var oRecordNum;
  208.                 var oMaxRecords;
  209.                 
  210.                 oRecordNum = document.getElementById("hdnRecordNum");
  211.                 oMaxRecords = document.getElementById("hdnMaxRecords");
  212.                 
  213.                 if ( oRecordNum != null && oMaxRecords != null )
  214.                 {
  215.                     var intRecordNum = parseInt(oRecordNum.value,10);
  216.                     var intMaxRecords = parseInt(oMaxRecords.value,10);
  217.  
  218.                     if (intRecordNum < intMaxRecords)
  219.                     {
  220.                         oRecordNum.value = intRecordNum + 1;
  221.                         document.TVData.submit();
  222.                     }
  223.                 }
  224.                 else
  225.                 {
  226.                     if ( oRecordNum == null)
  227.                     {
  228.                         if ( SA_IsDebugEnabled() )
  229.                         {
  230.                             alert("document.getElementById('hdnRecordNum') returned null");
  231.                         }
  232.                     }
  233.                     if ( oMaxRecords == null)
  234.                     {
  235.                         if ( SA_IsDebugEnabled() )
  236.                         {
  237.                             alert("document.getElementById('hdnMaxRecords') returned null");
  238.                         }
  239.                     }
  240.                 }
  241.             }
  242.             
  243.             //function to  previous event
  244.             function goPrevious()
  245.             {
  246.                 var oRecordNum;
  247.                 
  248.                 oRecordNum = document.getElementById("hdnRecordNum");
  249.                 if ( oRecordNum != null )
  250.                 {
  251.                     var intRecordNum = parseInt(oRecordNum.value,10);
  252.  
  253.                     if (intRecordNum > 0 )
  254.                     {
  255.                         oRecordNum.value = intRecordNum - 1;
  256.                         document.TVData.submit();
  257.                     }
  258.                 }
  259.                 else
  260.                 {
  261.                     if ( oRecordNum == null) 
  262.                     {
  263.                         if ( SA_IsDebugEnabled() )
  264.                         {
  265.                             alert("document.getElementById('hdnRecordNum') returned null");
  266.                         }
  267.                     }
  268.                 }
  269.             }
  270.  
  271.         </script>
  272.            
  273.    <%
  274.    End Function
  275.        
  276.     '-------------------------------------------------------------------------
  277.     'Function name:        GetFormVariables()
  278.     'Description:        Fetches state variables from form fields
  279.     'Input Variables:    None    
  280.     'Output Variables:    None
  281.     'Returns:            True - If GetDefaultValues function returns true
  282.     '                    False - Else
  283.     'Global Variables:    Input: None
  284.     '                    Output: G_strLogName - Log Name
  285.     '                    Output:    G_intRecordNumber - Current record number in the log
  286.     '-------------------------------------------------------------------------
  287.     Function GetFormVariables()
  288.     
  289.         G_strLogName = Request.Form("hdnLogName")
  290.         G_intRecordNumber = CInt(Request.Form("hdnRecordNum"))
  291.         G_intMaxRecords = CInt(Request.Form("hdnMaxRecords"))
  292.         G_intLowestRec = CInt(Request.Form("hdnMinRecords"))
  293.         
  294.         If GetDefaultValues() then
  295.             GetFormVariables=True
  296.         Else
  297.             GetFormVariables=False
  298.         End if   
  299.     End Function
  300.  
  301.         
  302.     '-------------------------------------------------------------------------
  303.     'Function name:        GetDefaultValues
  304.     'Description:        Serves in Getting the default values of the selected log 
  305.     'Input Variables:    None    
  306.     'Output Variables:    None
  307.     'Returns:            False - If error in retrieving values
  308.     '                    True - Else
  309.     'Global Variables:    Out:G_objService - WMI connection object
  310.     '                    In:G_strLogName - Log Name
  311.     '                    In:G_intRecordNumber - Current record number in the log
  312.     '                    In:F_strDate - Date the Event was logged
  313.     '                    In:F_strTime - Time the log event was created
  314.     '                    In:F_strType - Type of event
  315.     '                    In:F_strSource - Source of the log event
  316.     '                    In:F_intEventId - Id of the log event
  317.     '                    In:F_strDescription - Description of the log event
  318.     '-------------------------------------------------------------------------
  319.     Function GetDefaultValues()
  320.         Err.Clear 
  321.         On Error Resume Next
  322.     
  323.         Dim objLognames        'To store the results of the query
  324.         Dim strQuery        'To store the query
  325.         Dim objLog            'To process the result of the query
  326.         Dim intNoOfRecords    'Total records
  327.         Dim strLogType        'Type of log
  328.                 
  329.         Const CONST_wbemPrivilegeSecurity = 7        'Privilege constant
  330.         Const CONST_strSecurityLog = "SECURITY"        'Constant for security log
  331.  
  332.         Dim oValidator
  333.         Set oValidator = new CSAValidator
  334.         If ( FALSE = oValidator.IsValidIdentifier(G_strLogName)) Then
  335.             Call SA_TraceOut(SA_GetScriptFileName(), "LogName is invalid: " & G_strLogName)
  336.             Call SA_ServeFailurepage(L_RETREIVEVALUES_ERRORMESSAGE)
  337.             Set oValidator = Nothing
  338.             Exit Function
  339.         End If
  340.         Set oValidator = Nothing
  341.                                             
  342.         Set G_objService = GetWMIConnection(CONST_WMI_WIN32_NAMESPACE)
  343.         
  344.         If Ucase(G_strLogName) = CONST_strSecurityLog then
  345.             'G_objService.Security_.Privileges.Add CONST_wbemPrivilegeSecurity    'giving the req Privilege
  346.         End if
  347.                 
  348.         If Err.number <> 0 then
  349.             Call SA_TraceOut(SA_GetScriptFileName(), "G_objService.Security_.Privileges.Add failed: " + CStr(Hex(Err.Number)) + " " + Err.Description)
  350.             Call SA_ServeFailurepage(L_FAILEDTOGETWMICONNECTION_ERRORMESSAGE)
  351.             GetDefaultValues=False
  352.             Exit Function    
  353.         End If
  354.         
  355.         strQuery  ="SELECT * FROM  Win32_NTlogEvent WHERE Logfile=" & chr(34) & G_strLogName & chr(34) & "AND RecordNumber =" & cint(G_intRecordNumber)
  356.         Set objLognames = G_objService.ExecQuery(strQuery,"WQL",48,null)
  357.         
  358.         If Err.number <> 0 then
  359.             Call SA_TraceOut(SA_GetScriptFileName(), "G_objService.ExecQuery(strQuery,WQL,48) failed: " + CStr(Hex(Err.Number)) + " " + Err.Description)
  360.             Call SA_TraceOut(SA_GetScriptFileName(), "Query was: " + strQuery)
  361.             Call SA_ServeFailurepage(L_RETREIVEVALUES_ERRORMESSAGE)
  362.             GetDefaultValues=False
  363.             Exit Function    
  364.         End If
  365.         
  366.         For each objLog in objLognames 
  367.             F_strDate = Mid(objLog.TimeGenerated,5,2)& "/" & Mid(objLog.TimeGenerated,7,2) & "/" & Mid(objLog.TimeGenerated,1,4)
  368.             F_strTime = Mid(objLog.TimeGenerated,9,2)& ":" & Mid(objLog.TimeGenerated,11,2)& ":" & Mid(objLog.TimeGenerated,13,2) 
  369.             F_strType = objLog.Type
  370.             F_strSource = objLog.SourceName
  371.             F_intEventid= Cstr(objLog.EventCode)
  372.             F_strDescription=objLog.Message
  373.             
  374.             Exit For
  375.             
  376.         Next
  377.         
  378.         'Replace the carriagereturn string with null
  379.         F_strDescription = Replace(F_strDescription,VBCrLf,"")
  380.             
  381.         Select Case F_strType  
  382.         
  383.             case "information" :
  384.                 strLogType = L_INFORMATION_TYPE_TEXT
  385.             case "error" :
  386.                 strLogType = L_ERROR_TYPE_TEXT
  387.             case "warning" :
  388.                 strLogType = L_WARNING_TYPE_TEXT
  389.             case "audit success" :
  390.                 strLogType = L_SUCCESSAUDIT_TYPE_TEXT
  391.             case "audit failure" :
  392.                 strLogType = L_FAILUREAUDIT_TYPE_TEXT
  393.             case else
  394.                 strLogType = ""
  395.         End Select
  396.             
  397.         F_strType = strLogType
  398.         
  399.         'Get max records
  400.         If GetMaxRecords(G_strLogName,G_objService) then
  401.             GetDefaultValues=True
  402.         Else
  403.            GetDefaultValues=False 
  404.            Exit function
  405.         End if
  406.         
  407.         intNoOfRecords = getEventLogCount(G_strLogName,G_objService)
  408.         'Lowest record number
  409.         G_intLowestRec = G_intMaxRecords - intNoOfRecords + 1
  410.             
  411.         GetDefaultValues = true
  412.         
  413.         Set G_objService=Nothing
  414.         Set objLognames=Nothing
  415.         Set objLog = Nothing
  416.         
  417.     End Function
  418.     
  419.  
  420.     '-------------------------------------------------------------------------
  421.     'Function name:        GetMaxRecords
  422.     'Description:        gets the maximum records available from WMI
  423.     'Input Variables:    None    
  424.     'Output Variables:    None
  425.     'Returns:            True - If Maxrecords retrieved properly
  426.     '                    False - If error in retrieval of Maxrecords
  427.     'Global Variables:    Out:G_intMaxRecords - Maximum records in the log
  428.     '                    In:G_objService - WMI connection object
  429.     '                    In:G_strLogName - Log name
  430.     '-------------------------------------------------------------------------
  431.     Function GetMaxRecords(strLogName,strObjService)
  432.         On Error Resume Next
  433.         Err.Clear 
  434.         
  435.         Dim strQuery        'To store the query
  436.         Dim objLognames        'To store the results of the query
  437.         Dim objLog            'To process the results of the query
  438.                 
  439.         strQuery  ="SELECT * FROM  Win32_NTlogEvent WHERE Logfile=" & chr(34) & G_strLogName & chr(34)
  440.         Set objLognames = strObjService.ExecQuery(strQuery,"WQL",48,null)
  441.                 
  442.         If Err.number <> 0 then
  443.             Call SA_ServeFailurepage(L_FAILEDTOGETMAXLOGCOUNT_ERRORMESSAGE)
  444.             GetMaxRecords = false
  445.             Exit Function
  446.         End if
  447.         
  448.         For each objLog in objLognames 
  449.             G_intMaxRecords = objLog.RecordNumber
  450.             Exit for
  451.         Next
  452.         
  453.         If Err.number <> 0 then
  454.             Call SA_SetErrMsg (L_RETREIVEVALUES_ERRORMESSAGE)
  455.             GetMaxRecords=False
  456.             Exit Function    
  457.         End If
  458.         
  459.         GetMaxRecords=True
  460.         Set objLognames=nothing
  461.         Set objLog = nothing
  462.         
  463.     End Function    
  464.     
  465.     '-------------------------------------------------------------------------`
  466.     ' Function name:    getEventLogCount
  467.     ' Description:        returns Log Count
  468.     ' Input Variables:    strEventLogName - Log Name( Application,system,Security)
  469.     ' Output Variables:    None
  470.     ' Return Values:    Returns Log Count
  471.     ' Global Variables: L_FAILEDTOGETCOUNT_ERRORMESSAGE,G_objConnection,G_strReturnURL
  472.     ' Gets the instance of Logname and returns the count. 
  473.     '-------------------------------------------------------------------------
  474.     Function getEventLogCount(strEventLogName,objService)
  475.         Err.Clear 
  476.         On Error Resume Next
  477.             
  478.         Dim objLognames
  479.         Dim objLogname
  480.         Dim nRecordCount
  481.         nRecordCount = 0
  482.         
  483.         'Getting the instances of the Logfile
  484.         Set objLognames = objService.InstancesOf("Win32_NTEventlogFile")
  485.         
  486.         'Checking for recordcount if zero "No Events" 
  487.         If ( objLognames.count = 0 ) Then
  488.             nRecordCount = 0        
  489.         Else
  490.             For each objLogname in objLognames
  491.                 'checking for the selected logfilename if so get the record number for future use
  492.                 If LCase(objLogname.LogFileName)=LCase(strEventLogName) Then
  493.                     'Assigning the no of records for the selected Log
  494.                     If IsNull(objLogname.NumberOfRecords) Then
  495.                         nRecordCount = 0
  496.                     Else
  497.                         nRecordCount=CInt(objLogname.NumberOfRecords)
  498.                     End If    
  499.                     Exit For
  500.                 End If
  501.             Next
  502.         End IF
  503.         
  504.         'Set to nothing
  505.         Set objLogname = Nothing
  506.         Set objLognames =Nothing
  507.         
  508.         If Err.number  <> 0 Then
  509.             Call SA_ServeFailurepage(L_FAILEDTOGETCOUNT_ERRORMESSAGE)
  510.             getEventLogCount = false
  511.             Exit function
  512.         End If    
  513.         
  514.         getEventLogCount = nRecordCount
  515.         
  516.     End Function
  517. %>    
  518.